package com.nd.android.u.ui.widge.lift;

import java.util.ArrayList;
import java.util.Random;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.nd.android.u.ui.R;

public class PetalSet {

	public ArrayList<Petal> petalList;
	private final static int Y_POSITION = -100; // 花瓣出生在竖直方向的位置
	private final static int X_SEED = 0; // 花瓣掉落时，相对于X轴方向的速度
	private final static int Y_SEED =40; // 花瓣掉落时，相对于Y轴方向的速度
    private boolean isSelection;    //mSelection   对送蛋糕还是送鲜花的选择。    0  是蛋糕      1是鲜花
    private final static int FLOWER_IMAGE = R.drawable.lift_flower;
    private final static int[] CAKE_IMAGE=new int[]{R.drawable.cakeimg,R.drawable.cakeimg_thumb,R.drawable.candyimg,
    	                                                    R.drawable.candyimg_thumb,R.drawable.greenpaper,R.drawable.yellow_paper,
    	                                                    R.drawable.liftimg,R.drawable.liftimg_thumb,R.drawable.red_paper,
    	                                                    R.drawable.bluepaper,R.drawable.cakeimg_thumb,R.drawable.greenpaper,R.drawable.yellow_paper,
    	                                                    R.drawable.candyimg_thumb,R.drawable.liftimg_thumb,R.drawable.bluepaper,
    	                                                    R.drawable.greenpaper,R.drawable.bluepaper};

    
	public PetalSet(boolean selection) {    
		isSelection=selection;
		petalList = new ArrayList<Petal>();
	}

	/**
	 * 增加鲜花
	 */
	public void add(int count, double startTime, Resources res, int width) {
		for (int i = 0; i < count; i++) {
			Bitmap tempImage = BitmapFactory.decodeResource(res, getImageId());
			int tempX = (int) (0 + 3 * width * (Math.random() + 0.3) / 5); //设定花瓣掉落（相对于Ｘ轴）的范围    0.2-0.8的范围

			int tempY = Y_POSITION;
			int tempv_v = Y_SEED;
			int tempv_h = X_SEED;
			Petal petal = new Petal(tempImage, tempX, tempY, tempv_v, tempv_h,
					startTime);
			petalList.add(petal);
		}
	}

	/**
	 * 获取鲜花/蛋糕的图片ＩＤ
	 */
	public int getImageId() {
		int ImageId; 
		Random ran = new Random();
		if(!isSelection){             //选择蛋糕模式
			ImageId = CAKE_IMAGE[ran.nextInt(CAKE_IMAGE.length)];
		}else{                        //鲜花模式
			ImageId = FLOWER_IMAGE;
		}
		return ImageId;

	}
}
